package office.action.business;

import java.util.List;

import office.action.business.form.BidBookConditionForm;
import office.action.business.form.ContractConditionForm;
import office.action.business.form.ContractForm;
import office.action.business.wrapper.BidBookWrapper;
import office.action.business.wrapper.ContractWrapper;
import office.service.business.IBidBookService;
import office.service.business.IContractService;
import platform.common.action.BaseAction;
import platform.common.bo.Page;
import platform.util.Util;

/**
 * 
 * 采购采购合同管理
 * 
 * @author ZhangYQ
 * 
 */
public class StockContractAction extends BaseAction {
	
	private static final long serialVersionUID = 1L;
	private IContractService contractService;
	private IBidBookService bidBookService;
	private Page page; // 分页信息
	private List<ContractWrapper> wrapperList;
	private List<BidBookWrapper> bidBookWrapperList;
	private ContractForm form;
	private ContractConditionForm condition;
	private BidBookConditionForm bidBookCondition;
	private String id;

	/**
	 * 获取所有的采购合同以及根据条件进行查询
	 * 
	 * @return
	 * @throws Exception
	 */
	public String findAllStockContract() throws Exception {
		String result="listStockContractByPage";
		if(null==condition){
			result="findAllStockContract";
			condition=new ContractConditionForm();
		}
		condition.setContractType(Util.parsePropertiesReturnStr("office", "StockContract"));
		page = contractService.getPageInfo(condition);
		wrapperList = contractService.findAllContract(condition,page);
		return result;
	}

	/**
	 * 初始化编辑采购合同页面
	 * @return
	 * @throws Exception
	 */
	public String gotoEditStockContract() throws Exception {
		if(null!=id&&!"".equals(id)){
			form = contractService.getById(id);
		}
		bidBookWrapperList=bidBookService.findAllBidBookByStatus(bidBookCondition);
		return "gotoEditStockContract";
	}

	/**
	 * 编辑采购合同
	 * 
	 * @return
	 * @throws Exception
	 */
	public String editStockContract() throws Exception {
		try {
			contractService.editContract(form);
			if (null == form.getId()
					|| ("").equals(form.getId())) {
				this.getAjaxMessagesJson().setMessage(true, "", "新建成功");
			} else {
				this.getAjaxMessagesJson().setMessage(true, "", "编辑成功");
			}

		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}

	/**
	 * 
	 * <br/>
	 * 方法描述:分页条件查询采购合同
	 * 
	 * @return
	 * @throws Exception
	 */
	public String listStockContractByPage() throws Exception {
		try {
			if(null==condition){
				condition=new ContractConditionForm();
			}
			condition.setContractType(Util.parsePropertiesReturnStr("office", "StockContract"));
			wrapperList = contractService.findAllContract(condition, page);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			throw e;
		}
		return "listStockContractByPage";
	}

	/**
	 * 初始化采购合同列表操作菜单
	 * 
	 * @return
	 * @throws Exception
	 */

	public String gotoStockContractMenu() throws Exception {
		return "gotoStockContractMenu";
	}

	/**
	 * 跳转到采购合同删除确认页面
	 */
	public String gotoDeleteStockContract(){
		return "gotoDeleteStockContract";
	}
	
	/**
	 * 删除采购合同
	 * @return
	 * @throws Exception
	 */
	public String delStockContract() throws Exception {
		try {
			contractService.delContractById(id);
			this.getAjaxMessagesJson().setMessage(true, "", "操作成功");
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			throw e;
		}
		return RESULT_AJAXJSON;
	}

	public IContractService getContractService() {
		return contractService;
	}

	public void setContractService(IContractService contractService) {
		this.contractService = contractService;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public List<ContractWrapper> getWrapperList() {
		return wrapperList;
	}

	public void setWrapperList(List<ContractWrapper> wrapperList) {
		this.wrapperList = wrapperList;
	}

	public ContractForm getForm() {
		return form;
	}

	public void setForm(ContractForm form) {
		this.form = form;
	}

	public ContractConditionForm getCondition() {
		return condition;
	}

	public void setCondition(ContractConditionForm condition) {
		this.condition = condition;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public List<BidBookWrapper> getBidBookWrapperList() {
		return bidBookWrapperList;
	}

	public void setBidBookWrapperList(List<BidBookWrapper> bidBookWrapperList) {
		this.bidBookWrapperList = bidBookWrapperList;
	}

	public IBidBookService getBidBookService() {
		return bidBookService;
	}

	public void setBidBookService(IBidBookService bidBookService) {
		this.bidBookService = bidBookService;
	}

	public BidBookConditionForm getBidBookCondition() {
		return bidBookCondition;
	}

	public void setBidBookCondition(BidBookConditionForm bidBookCondition) {
		this.bidBookCondition = bidBookCondition;
	}
	
}
